<include file="Public/header"/>
<include file="Public/menu"/>
<style>
    .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{
        vertical-align:middle;
    }
</style>
<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            首页
            <small>结算</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">店铺结算账单</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content">

        <div class="tab-content">
            <div class="tab-pane active" id="tab_0">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title"></h3>
                        <div class="form-inline pull-right">
                            <form action="{:U('Bills/add')}" method="get">
                                <fieldset>
                                    <div class="btn-group">时间段</div>
                                    <div class="input-group" >
                                        <input class="form-control" type="text" id="start_time" name="start_time" value="{$_GET['start_time']}" readonly placeholder="开始日期">
                                    </div>
                                    <div class="btn-group">-</div>
                                    <div class="input-group" >
                                        <input class="form-control" type="text" id="end_time" name="end_time" value="{$_GET['end_time']}" readonly placeholder="结束日期">
                                    </div>
                                    <select class="form-control" name="local_id" style="height: 30px; font-size: 12px;">
                                        <option value="" <if condition="local_id eq ''">selected="selected"</if>>门店名称</option>
                                        <volist name="locals" id="vo">
                                            <option value="{$vo.local_id}" <if condition="$vo['local_id'] eq $_GET['local_id']">selected="selected"</if>>{$vo.local_name}</option>
                                        </volist>
                                    </select>

                                    <div class="input-group input-group-sm">
                                        <div class="input-group-btn">
                                            <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i>
                                            </button>
                                        </div>
                                    </div>
                                </fieldset>
                            </form>
                        </div>


                    </div>
                    <!-- /.box-header -->
                    <form action="{:U('Bills/save')}"  method="post" onSubmit="return checkSettleSubmit();">
                    <if condition="$order neq ''">
                        <div class="box-header" style="background-color: #fbed50">
                            <h3 class="box-title">结算明细</h3>
                        </div>
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover" id="order-table-list">
                                <tbody>
                                <tr>
                                    <th>ID</th>
                                    <th>订单号</th>
                                    <th>数量</th>
                                    <th>佣金率</th>
                                    <th>抽佣金额</th>
                                    <th>门店优惠</th>
                                    <th>使用奖金</th>
                                    <th>物流费用</th>
                                    <th>订单金额</th>
                                    <th>实支付金额</th>
                                    <th>支付日期</th>
                                    <th>支付方式</th>
                                    <th>操作</th>
                                </tr>
                                <volist name="order" id="vo" key="key">
                                <tr class="one-order-area">
                                    <td>{$key}</td>
                                    <td>
                                    	<a href="{:U('orders/orderDetail',array('id'=>$vo['order_id']))}">{$vo.order_id}</a>
                                        <input type="hidden" name="order[]" value="{$vo.order_id}">
                                    </td>                                    
                                    <if condition="$vo['geshu'] gt 1">
                                        <td>
                                            <table>
                                                <volist name="vo['list']" id="v">
                                                <tr>
                                                    <td>{$v.name}</td>
                                                </tr>
                                                </volist>
                                            </table>
                                        </td>
                                        <td>
                                            <table>
                                                <volist name="vo['list']" id="v">
                                                    <tr>
                                                        <td>{$v.yc_rate}%</td>
                                                    </tr>
                                                </volist>
                                            </table>
                                        </td>
                                        <td>
                                            <table>
                                                <volist name="vo['list']" id="v">
                                                    <tr>
                                                        <td>{$v.yc_fee}</td>
                                                    </tr>
                                                </volist>
                                            </table>
                                        </td>
                                        <!--<td>-->
                                            <!--<table>-->
                                                <!--<volist name="vo['list']" id="v">-->
                                                    <!--<tr>-->
                                                        <!--<td>{$v.youhui}</td>-->
                                                    <!--</tr>-->
                                                <!--</volist>-->
                                            <!--</table>-->
                                        <!--</td>-->
                                    <else />
                                        <td>{$vo['list'][0]['name']}</td>
                                        <td>{$vo['list'][0]['yc_rate']}%</td>
                                        <td>{$vo['list'][0]['yc_fee']}</td>
                                        <!--<td>{$vo['list'][0]['youhui']}</td>-->
                                    </if>
                                    <td>
                                        <?php
                                        $a = bcadd($vo['cost_freight'], $vo['cost_item'], 2);
                                        echo bcsub($a ,$vo['total_amount'], 2);
                                    ?>

                                    </td>
                                    <td>{$vo.bonus_money}</td>
                                    <td>{$vo.cost_freight}</td>
                                    <td>{$vo.cost_item}</td>
                                    <td class="grid-order" data-yjfee="{$vo.yongjin|default=0}" data-cost="{$vo['total_amount']}" data-bonus="{$vo['bonus_money']|default=0}">{$vo['total_amount']}</td>
                                    <td>{$vo.createtime|date='Y-m-d H:i:s', ###}</td>
                                    <td>{$vo.paymethod_name|default='-'}</td>
                                    <td>
                                        <a href="javascript:void(0);" data-id="{$key}" class="grid-delete">移除</a>
                                    </td>
                                </tr>
                                </volist>
                                </tbody>
                            </table>
                        </div>
                        <div class="box-header" style="background-color:#ccc">
                            <h3 class="box-title">入账共计</h3>
                        </div>
                        <div class="box-body table-responsive no-padding" style="width:60%;">
                            <table class="table table-hover">
                                <tbody>
                                <tr>
                                    <th>订单数量</th>
                                    <th>订单实支付总金额</th>
                                    <th>抽佣总额</th>
                                    <th>奖金使用总额</th>
                                    <th>银行手续费</th>
                                    <th>其他手续费</th>
                                    <th>应结算总金额</th>
                                </tr>
                                <tr>
                                    <td><span id="zj-order-num">{$statistics.order_num}</span></td>
                                    <td><span id="zj-order-totalcost">{$statistics.total_money}</span></td>
                                    <td><span id="zj-order-totalyj">{$statistics.commission}</span></td>
                                    <td><span id="zj-use-bonus">{$statistics.use_bonus}</span></td>
                                    <td><input id="zj-order-bank" data-key="order-bank" name="bank" type="text" class="form-control" value="0.00"></td>
                                    <td><input id="zj-order-other" data-key="order-other" name="other" type="text" class="form-control" value="0.00"></td>
                                    <td><span id="zj-order-finalfee">正在计算...</span></td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                        <div>公式 ： 应结算金额 =  订单支付总额  - 抽佣总额   - 银行手续费 - 其他手续费 - 奖金使用金额</div>
                        <div style="height: 100px;"></div>
                    </if>
                    <!-- /.box-body -->
                    <if condition="$refund neq ''">
                        <div class="box-header" style="background-color: #fbed50">
                            <h3 class="box-title">退款明细</h3>
                        </div>
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover" id="refund-table-list">
                                <tbody>
                                <tr>
                                    <th>ID</th>
                                    <th>订单号</th>
                                    <th>商品</th>
                                    <th>佣金率</th>
                                    <th>抽佣金额</th>
                                    <th>退款金额</th>
                                    <th>返还奖金</th>
                                    <th>退款完成日期</th>
                                    <th>门店经办</th>
                                    <th>退款经办</th>
                                    <th>操作</th>
                                </tr>
                                <volist name="refund" id="vo" key="key">
                                    <tr  class="one-refund-area">
                                        <td>{$key}</td>                                        
                                        <td>
                                        	{$vo.order_id}
                                            <input type="hidden" name="refund[]" value="{$vo.order_id}">
                                        </td>
                                        <if condition="$vo['geshu'] gt 1">
                                            <td>
                                                <table>
                                                    <volist name="vo['list']" id="v">
                                                        <tr>
                                                            <td>{$v.name}</td>
                                                        </tr>
                                                    </volist>
                                                </table>
                                            </td>
                                            <td>
                                                <table>
                                                    <volist name="vo['list']" id="v">
                                                        <tr>
                                                            <td>{$v.yc_rate}%</td>
                                                        </tr>
                                                    </volist>
                                                </table>
                                            </td>
                                            <td>
                                                <table>
                                                    <volist name="vo['list']" id="v">
                                                        <tr>
                                                            <td>{$v.yc_fee}</td>
                                                        </tr>
                                                    </volist>
                                                </table>
                                            </td>
                                            <else />
                                            <td>{$vo['list'][0]['name']}</td>
                                            <td>{$vo['list'][0]['yc_rate']}%</td>
                                            <td>{$vo['list'][0]['yc_fee']}</td>
                                        </if>
                                        <td class="grid-refund" data-yjfee="{$vo.yongjin|default=0}" data-cost="{$vo.price_detail|default=0}" data-bonus="{$vo['bonus_money']|default=0}">{$vo.price_detail}</td>
                                        <td>{$vo.bonus_money}</td>
                                        <td>{$vo.finance_confirm_t|date='Y-m-d H:i:s', ###}</td>
                                        <td>{$vo.store_name}</td>
                                        <td>{$vo.finance_name}</td>
                                        <td>
                                            <a href="javascript:void(0);" data-id="{$key}" class="grid-delete">移除</a>
                                        </td>
                                    </tr>
                                </volist>
                                </tbody>
                            </table>
                        </div>
                        <div class="box-header" style="background-color:#ccc">
                            <h3 class="box-title">退款共计</h3>
                        </div>
                        <div class="box-body table-responsive no-padding" style="width:50%;" id="refundZ_div">
                            <table class="table table-hover">
                                <tbody>
                                    <tr>
                                        <th>订单数量</th>
                                        <th>订单退款总金额</th>
                                        <th>抽佣总额</th>
                                        <th>返还奖金总额</th>
                                        <th>其他返款</th>
                                        <th>应退款总金额</th>
                                    </tr>
                                	<tr>
                                        <td><span id="zj-refund-num">{$statistics2.refund_num}</span></td>
                                        <td><span id="zj-refund-totalcost">{$statistics2['total_money']}</span></td>
                                        <td><span id="zj-refund-totalyj">{$statistics2.commission}</span></td>
                                        <td><span id="zj-refund-bonus">{$statistics2.refund_bonus}</span></td>
                                        <td><input id="zj-refund-other" data-key="refund-other" name="other2" type="text" class="form-control" value="0.00"></td>
                                        <td><span id="zj-refund-finalfee">正在计算...</span></td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        <div>公式 ： 应退款总金额 = 订单退款总金额 - 退款返还的抽佣金额 - 其他返款 - 奖金返回金额</div>
                        <div style="height: 100px;"></div>
                    </if>
                    <if condition="$order neq '' or $refund neq ''">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="box-body">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">经办人</label>
                                        <div class="col-sm-10">
                                            <input type="text" class="form-control" id="handle_name" name="handle_name" value="<?php echo session('manageInfo')['login_name'];?>" placeholder="经办人" readonly>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">备注</label>

                                        <div class="col-sm-10">
                                            <textarea class="form-control" rows="3" placeholder="备注" name="handle_tips"></textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div>公式 ： 实际结算金额  =  应结算金额 - 应退款总金额</div>
                                <div><strong>本次结算实际金额:</strong><label class="label label-danger" style="font-size:15px;" id="current-js-fianlfee">正在计算...</label></div>
                            </div>
                        </div>
                        <div>
                            <input type="hidden" name="start_time" value="{$_GET['start_time']}">
                            <input type="hidden" name="end_time" value="{$_GET['end_time']}">
                            <input type="hidden" name="local_id" value="{$_GET['local_id']}">
                            <button class="btn btn-primary btn-lg" type="submit">创建结算对账单</button>
                        </div>
                    </if>
                    </form>
                </div>
            </div>

        </div>
    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer"/>
<link rel="stylesheet" href="/Public/admin/jedate/jedate.css" />
<script src="/Public/admin/jedate/jedate.js"></script>
<script type="text/javascript">
    // 设置时间
    function setJedate(){
        var start = {
            dateCell: '#start_time',
            format: 'YYYY-MM-DD',
            minDate: '1970-01-01 00:00:00',
            festival: false,
            maxDate: '2099-12-31 23:59:59',
            isinitVal:true,
            isTime: true,
            choosefun: function(datas) {
                end.minDate = datas; 
            }
        };
        var end = {
            dateCell: '#end_time',
            format: 'YYYY-MM-DD',
            minDate: '1970-01-01 00:00:00',
            festival: false,
            maxDate: '2099-12-31 23:59:59',
            isinitVal:true,
            isTime: true,
            choosefun: function(datas) {
                start.maxDate = datas;
            }
        };
        jeDate(start);
        jeDate(end);
    }
    setJedate();
</script>
<script type="text/javascript" src="/Public/admin/js/com.bill.js.js"></script>